package peer;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;

import protocols.Protocol;

public abstract class Connection implements Runnable{
	
	protected Peer callback;
		public Peer getCallback() { return this.callback; }
	protected HashMap<String,LinkedBlockingQueue> msgQueue;
	
	/**
	 * List of supported protocols
	 */
	protected HashMap<String, Protocol> protocols;
	
	private Connection() {

	}
	
	public Connection(Peer _callback) {
		protocols = new HashMap<String, Protocol>();
		msgQueue = new HashMap<String,LinkedBlockingQueue>();
		this.callback = _callback;
	}
	
	
	public abstract void close();
	public abstract Object read(String protocol);
	public abstract void write(Object m);
	public void registerProtocol(String name, Protocol protocol) {
		protocols.put(name, protocol);
		msgQueue.put(name, new LinkedBlockingQueue());
	}
}